package sample.kafka.consumer.listener;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.kafka.support.KafkaHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

@Component
public class DyzTopicListener {

    private static final Logger log= LoggerFactory.getLogger(DyzTopicListener.class);

    /**
     * id:消费者的IDDyzTopicListener
     * topics：监听的topic（可以多个）
     * groupId：消费者所属的消费者组
     *
     */
    @KafkaListener(id = "demoListener", topics = "dyz-topic" , groupId = "dyz-group")
    public void listen(ConsumerRecord record, Acknowledgment ack) {
        log.info("demoListener已在dyz-topic下消费消息。key= "+ record.key()+"; value="+record.value());
        ack.acknowledge();
    }
}
